package com.aaa.controller.sas;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.sas.QuestionSasVo;
import com.aaa.entity.sas.ViewTestResultSas;
import com.aaa.service.sas.ViewTestResultSasService;
import com.github.pagehelper.Page;
import lombok.extern.java.Log;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultSas)表控制层
 *
 * @author makejava
 * @since 2022-09-02 19:25:36
 */
@Log
@RestController
@RequestMapping("viewTestResultSas")
public class ViewTestResultSasController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultSasService viewTestResultSasService;


    /**
     * 新增数据
     *
     * @param viewTestResultSas 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ViewTestResultSas> add(ViewTestResultSas viewTestResultSas) {
        return ResponseEntity.ok(this.viewTestResultSasService.insert(viewTestResultSas));
    }


    /**
     * 测试结果
     *
     * @param modelAndView
     * @return
     */
    @RequestMapping("toShowTestResultSas.do")
    public ModelAndView toShowTestResultSas(ModelAndView modelAndView) {
        modelAndView.setViewName("sas/viewTestResultSas");
        return modelAndView;
    }

    /**
     * 报表统计
     *
     * @param modelAndView
     * @return
     */
    @RequestMapping("toReportFormsSas.do")
    public ModelAndView toReportFormsSas(ModelAndView modelAndView) {
        modelAndView.setViewName("sas/reportFormsSas");
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param pageSortEntity
     * @param viewTestResultSas
     * @return
     */
    @RequestMapping("queryResult.do")
    public Result queryResult(PageSortEntity pageSortEntity, ViewTestResultSas viewTestResultSas) {
        List<ViewTestResultSas> viewTestResultSas1 = viewTestResultSasService.queryResult(pageSortEntity, viewTestResultSas);
        Page<ViewTestResultSas> page = (Page) viewTestResultSas1;
        return success(page.getResult(), page.getTotal());
    }


    /**
     * 下拉框数据
     *
     * @return
     */
    @RequestMapping("pullSas.do")
    public Result pullSas() {
        List<ViewTestResultSas> viewTestResultSas1 = viewTestResultSasService.queryAllPlan();
        return success(viewTestResultSas1);
    }

    /**
     * 删除、批量删除
     */
    @RequestMapping("delete.do")
    public Result delete(int[] id) {
        boolean delete = viewTestResultSasService.delete(id);
        if (delete) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 通过id查询结果
     *
     * @param viewTestResultSas
     * @return
     */
    @RequestMapping("queryResultById.do")
    public Result queryResultById(ViewTestResultSas viewTestResultSas) {
        ViewTestResultSas viewTestResultSas1 = viewTestResultSasService.queryResultById(viewTestResultSas);
        return success(viewTestResultSas1);
    }

    /**
     * 报表查询
     *
     * @return
     */
    @RequestMapping("showResult.do")
    public Result showResult() {
        Map<String, Integer> stringIntegerMap = viewTestResultSasService.queryAll();
        return success(stringIntegerMap);
    }

    @GetMapping("showDetails.do")
    public Result showDetails(Integer testerId){
        List<QuestionSasVo> questionSasVos = viewTestResultSasService.queryDetail(testerId);
        if (ObjectUtil.isNotEmpty(questionSasVos)&&questionSasVos.size()>0){
            return success(questionSasVos);
        }else {
            return fail();
        }
    }

}

